module Shamela
  Document = Struct.new(:id,:nass,:part,:page,:hno,:Sora,:Aya,:na,
    :section,:position, :type)
  class Document
    def initialize(csv_row=nil, header=nil)
      if csv_row == nil && header == nil
        return
      end
      if header.include?('Aya') || header.include?('Sura')
        self.type = 'Aya'
      else
        self.type = 'Hadith'
      end
      header.each_with_index do |name, i|
        self.send("#{name}=", csv_row[i])
      end
    end
    
    def to_db
      d = ::Document.new(:body=>self.nass, :position=>self.position,
        :document_no=>self.Aya)
      d.type = self.type
      return d
    end
    
  end
end
